//
//  Icons.swift
//  CodingTest
//
//  Created by LYPC on 2021/11/18.
//

import UIKit

// MARK:- 图标相关
public extension UIImage {
    static func icon(_ icon: Icons) -> UIImage? {
        return getImage(icon.rawValue)
    }
}

public extension Optional where Wrapped: UIImage {
    static func icon(_ icon: Icons) -> UIImage? {
        return getImage(icon.rawValue)
    }
}

public enum Icons: String {
    case nav_back
    case placeholder_empty
    case placeholder_error
}

// MARK:- 通过名称获取UIImage
public func getImage(_ imgName: String) -> UIImage? {
    if let image = UIImage(named: imgName) {
        return image
    } else {
        k_log("🔴 generate image: \(imgName) failed 🔴")
        return nil
    }
}
